package test;

public class Solution {

    public boolean isPalindrome(String s) {
        s=s.toLowerCase();
        StringBuilder s1 = new StringBuilder();
        for(int i=0;i<s.length();i++){
            if((s.charAt(i)>='a'&&s.charAt(i)<='z')||(s.charAt(i)>='0'&&s.charAt(i)<='9'))
            {
                s1.append(s.charAt(i));
            }
        }
        //System.out.println(s1);
        StringBuilder s2 = new StringBuilder(s1);
        String s3=s2.reverse().toString();
        String s4=s1.toString();
        return(s3.equals(s4));

    }



    /*
     private boolean isCharacter(char ch){
         if(ch>='a'&&ch<='z'||ch>='0'&&ch<='9'){
            return true;
         }
        return false;
     }
    public boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int i=0;
        int j=s.length()-1;
        while (i<j){
            while (i<j&&!isCharacter(s.charAt(i))){
                i++;
            }
            while (i<j&&!isCharacter(s.charAt(j))){
                j--;
            }
            if(s.charAt(i)!=s.charAt(j)){
                return false;
            }else {
                i++;
                j--;
            }
        }
        return true;

    }

     */
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.isPalindrome("A man, a plan, a canal: Panama"));
    }
}
